home *** CD-ROM | disk | FTP | other *** search
- import java.io.ByteArrayInputStream;
- import java.io.ByteArrayOutputStream;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.midlet.MIDlet;
- import javax.microedition.midlet.MIDletStateChangeException;
- import javax.microedition.rms.RecordStore;
- import javax.microedition.rms.RecordStoreException;
-
- public class BlockBuster extends MIDlet implements CommandListener, Runnable {
- private Command CmdExit = new Command("exit", 1, 2);
- private Command CmdStart = new Command("Start", 1, 3);
- private Command CmdPlay = new Command("play", 1, 3);
- private Command Cmdstop = new Command("stop", 1, 4);
- private Command CmdReStart = new Command("Start", 1, 3);
- private Display display = Display.getDisplay(this);
- private Court court = new Court(this);
- private MsgBox mbox = new MsgBox();
- private boolean paused = true;
- private int StageNo;
- private int gamespeed = 60;
- private RecordStore RStore;
- private Thread gameThread;
- private int highScoreID;
-
- public BlockBuster() {
- this.mbox.addCommand(this.CmdStart);
- this.mbox.addCommand(this.CmdExit);
- this.mbox.setCommandListener(this);
- this.StageNo = 0;
- this.RStore = null;
- this.showTitle();
- }
-
- public void FirstStart() {
- try {
- this.display.setCurrent(this.mbox);
- MsgBox.stgNum = 1;
- MsgBox.msgType = 1;
- this.mbox.repaint();
- Thread.sleep(650L);
- this.mbox.removeCommand(this.CmdStart);
- this.mbox.removeCommand(this.CmdExit);
- } catch (InterruptedException var1) {
- }
-
- this.StageNo = 1;
- this.court.addCommand(this.CmdPlay);
- this.court.addCommand(this.CmdExit);
- this.display.setCurrent(this.court);
- this.court.setCommandListener(this);
- }
-
- public void ShowMsg(int var1) {
- try {
- this.display.setCurrent(this.mbox);
- MsgBox.mscore = Court.score;
- MsgBox.hiscore = Court.hiscore;
- MsgBox.stgNum = this.StageNo;
- MsgBox.msgType = var1;
- this.mbox.repaint();
- if (var1 == 3 || var1 == 5) {
- this.WriteHiScore();
- this.mbox.addCommand(this.CmdReStart);
- this.mbox.addCommand(this.CmdExit);
- this.mbox.setCommandListener(this);
- return;
- }
-
- Thread.sleep(1000L);
- this.display.setCurrent(this.court);
- Court.Msging = false;
- } catch (InterruptedException var2) {
- }
-
- }
-
- public void SlowDown() {
- this.gamespeed += 5;
- if (this.gamespeed > 90) {
- this.gamespeed = 90;
- }
-
- }
-
- public void SpeedUp() {
- this.gamespeed -= 5;
- if (this.gamespeed < 30) {
- this.gamespeed = 30;
- }
-
- }
-
- void ThreadStart() {
- this.gameThread = new Thread(this);
- this.gameThread.start();
- }
-
- public void WriteHiScore() {
- if (this.RStore != null) {
- ByteArrayOutputStream var1 = new ByteArrayOutputStream();
- DataOutputStream var2 = new DataOutputStream(var1);
-
- try {
- var2.writeInt(Court.hiscore);
- } catch (IOException var5) {
- }
-
- byte[] var3 = var1.toByteArray();
-
- try {
- this.RStore.setRecord(this.highScoreID, var3, 0, var3.length);
- } catch (RecordStoreException var4) {
- }
-
- }
- }
-
- public void commandAction(Command var1, Displayable var2) {
- if (var1 == this.CmdExit) {
- this.WriteHiScore();
- this.destroyApp(false);
- ((MIDlet)this).notifyDestroyed();
- } else if (var1 == this.CmdStart) {
- this.ThreadStart();
- this.FirstStart();
- this.court.Playing = true;
- Court.Msging = false;
- } else if (var1 == this.CmdReStart) {
- this.court.ChgMsgStatus(0);
- this.StageNo = 1;
- this.display.setCurrent(this.court);
- Court.score = 0;
- Court.life = 3;
- Court.Msging = false;
- this.court.GoNext(this.StageNo);
- this.court.removeCommand(this.Cmdstop);
- this.court.addCommand(this.CmdPlay);
- this.court.BallMove(false);
- this.mbox.removeCommand(this.CmdReStart);
- } else if (var1 == this.CmdPlay) {
- this.court.Playing = true;
- this.court.BallMove(true);
- this.court.removeCommand(this.CmdPlay);
- this.court.addCommand(this.Cmdstop);
- } else if (var1 == this.Cmdstop) {
- this.court.Playing = false;
- this.court.removeCommand(this.Cmdstop);
- this.court.addCommand(this.CmdPlay);
- }
-
- }
-
- public void destroyApp(boolean var1) {
- this.WriteHiScore();
- }
-
- public void load() {
- Object var1 = null;
- if (this.RStore != null) {
- try {
- if (this.RStore.getNumRecords() == 0) {
- Court.hiscore = 0;
- ByteArrayOutputStream var2 = new ByteArrayOutputStream();
- DataOutputStream var3 = new DataOutputStream(var2);
-
- try {
- var3.writeInt(Court.hiscore);
- } catch (IOException var5) {
- }
-
- byte[] var4 = var2.toByteArray();
- this.highScoreID = this.RStore.addRecord(var4, 0, var4.length);
- } else {
- this.highScoreID = this.RStore.getNextRecordID();
- if (this.highScoreID > 0) {
- --this.highScoreID;
- byte[] var7 = this.RStore.getRecord(this.highScoreID);
- if (var7 != null) {
- ByteArrayInputStream var8 = new ByteArrayInputStream(var7);
- DataInputStream var9 = new DataInputStream(var8);
- Court.hiscore = var9.readInt();
- } else {
- Court.hiscore = 0;
- }
- }
- }
- } catch (Exception var6) {
- }
-
- }
- }
-
- void pause() {
- this.paused = true;
- }
-
- public void pauseApp() {
- this.pause();
- }
-
- public void run() {
- this.paused = false;
-
- while(!this.paused) {
- this.court.moveBall();
-
- try {
- Thread.sleep((long)this.gamespeed);
- } catch (InterruptedException var1) {
- }
-
- if (this.StageNo == 0) {
- this.FirstStart();
- }
-
- if (this.court.GetMsgStatus() == 2) {
- this.ShowMsg(2);
- ++this.StageNo;
- this.ShowMsg(1);
- this.court.ChgMsgStatus(0);
- this.court.GoNext(this.StageNo);
- this.court.removeCommand(this.Cmdstop);
- this.court.addCommand(this.CmdPlay);
- this.court.BallMove(false);
- } else if (this.court.GetMsgStatus() != 0 && this.court.GetMsgStatus() != 2) {
- this.ShowMsg(this.court.GetMsgStatus());
- this.court.ChgMsgStatus(0);
- this.court.removeCommand(this.Cmdstop);
- this.court.addCommand(this.CmdPlay);
- }
-
- this.court.moveBall();
- this.court.repaint();
- }
-
- }
-
- public void setSpeed(int var1) {
- this.gamespeed = var1;
- }
-
- public void showTitle() {
- this.display.setCurrent(this.mbox);
- MsgBox.msgType = 0;
- this.mbox.repaint();
- }
-
- public void startApp() throws MIDletStateChangeException {
- try {
- this.RStore = RecordStore.openRecordStore("HiScoreDB", true);
- } catch (Exception var1) {
- }
-
- Court.hiscore = 0;
- this.load();
- }
- }
-